package demo4;

import java.io.*;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-08-08
 * Time: 18:17
 */
public class TestDemo5 {

    public static void main(String[] args) {
        System.out.println("请输入源文件路径");
        Scanner scan = new Scanner(System.in);
        String root = scan.next();
        File src = new File(root);
        if(!src.exists()){
            System.out.println("该源文件路径不存在");
            return;
        }
        if(!src.isFile()){
            System.out.println("该文件不是普通的文件");
            return;
        }
        System.out.println("请输入你要目的地路径");
        Scanner scanner = new Scanner(System.in);
        String destPath = scanner.next();
        File destFile = new File(destPath);
        if(destFile.exists()){
            System.out.println("该文件已经存在");
            return;
        }
        try(InputStream inputStream = new FileInputStream(src)){
            try(OutputStream outputStream = new FileOutputStream(destFile)){
                byte[] bytes = new byte[1024];
                while(true){
                    int len = inputStream.read();
                    if(len==-1){
                        break;
                    }
                    outputStream.write(bytes,0,len);
                }
            }
        }catch(IOException e){
            e.printStackTrace();
        }

    }

}
